const express = require('express');
const router = express.Router();

const MVOModule=require('../database/module/MVOModule');
const userInfoModule=require('../database/module/userInfoModule');
const BVOModule=require('../database/module/bvoModule');

async function findUsersInfo(list, ret) {
    for(let i=0;i<list.length;i++) {
        await userInfoModule.findOne({user_id:list[i].user_id}).then(data => {
            let userInfo = {
                user_id: data.user_id,
                bvo_id: list[i].bvo_id,
                mvo_id: list[i].mvo_id,
                name: data.name,
                balance: data.balance,
                avatar_url: data.avatar_url
            }
            ret.push(userInfo);
        })
    }
}

//查询所有品牌商
router.all('/findAllMVO',(req,res)=>{
    let ret = [];
    MVOModule.find().then(mvo_data=> {
        findUsersInfo(mvo_data, ret).then(()=> {
            res.send(ret);
        })
    })
})
//查询所有借卖方
router.all('/findAllBVO',(req,res)=>{
    let ret = [];
    BVOModule.find().then(bvo_data=>{
        findUsersInfo(bvo_data, ret).then(()=> {
            res.send(ret);
        })
    })
})

module.exports = router;